// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <gtest/gtest.h>
#include <pollux/common/base/pollux_exception.h>
#include <pollux/expression/expr.h>
#include <pollux/testing/functions/prestosql/function_base_test.h>

using namespace kumo::pollux;
using namespace kumo::pollux::exec;
using namespace kumo::pollux::functions::test;

class IntegerFunctionsTest : public FunctionBaseTest {};
TEST_F(IntegerFunctionsTest, xxHash64FunctionBigInt) {
  const auto xxhash64 = [&](std::optional<int64_t> value) {
    return evaluateOnce<int64_t>("xxhash64_internal(c0)", BIGINT(), value);
  };

  EXPECT_EQ(std::nullopt, xxhash64(std::nullopt));
  EXPECT_EQ(-6977822845260490347, xxhash64(1));
  EXPECT_EQ(3803688792395291579, xxhash64(0));
  EXPECT_EQ(-5379971487550586029, xxhash64(42));
  EXPECT_EQ(6443982544387243708, xxhash64(-100));
  // int64_t max
  EXPECT_EQ(-40307683044198644, xxhash64(9223372036854775807));
  EXPECT_EQ(310259422537775556, xxhash64(-9223372036854775807));
}
